package com.basics.framework.redission;


import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.io.Serializable;
import java.util.concurrent.TimeUnit;

@Data
public class DelayMessage implements Serializable {

    private String queueName;

    private Long delayTime;

    private TimeUnit timeUnit;

    private String msgBody;

    public DelayMessage(){

    }

    public DelayMessage(String queueName,Long delayTime,TimeUnit timeUnit,String msgBody){
        this.queueName = queueName;
        this.delayTime = delayTime;
        this.timeUnit = timeUnit;
        this.msgBody = msgBody;
    }

    /**
     * 延迟处理订单
     * @param msgBody
     * @return
     */
    public static DelayMessage order(String msgBody){
        return new DelayMessage(RedisDelayQueueEnum.ORDER_PAYMENT_TIMEOUT.getCode(),
                30l,TimeUnit.MINUTES,msgBody
                );
    }

    /**
     * 添加延迟处理公共账户
     * @param msgBody
     * @return
     */
    public static DelayMessage addAccount(String msgBody){
        return new DelayMessage(RedisDelayQueueEnum.ADD_CLASS_ACCOUNT.getCode(),
                1l,TimeUnit.MILLISECONDS,msgBody
        );
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}

